#! /usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'abcdefg'
__time__ = '20/06/18 下午7:28'

import logging
from redis import StrictRedis


class Config(object):
    """项目配置类"""
    DEBUG = True

    # 配置MYSQL连接
    SQLALCHEMY_DATABASE_URI = "mysql://root:123456@127.0.0.1/information"
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    # 如果此配置为True 在请求结束的时候会自动db.session.commit()
    SQLALCHEMY_COMMIT_ON_TEARDOWN = True

    # 配置redis
    REDIS_HOST = '127.0.0.1'
    REDIS_PORT = 6379

    # base64.b64encode(os.urandom(48)) 随机字符设置Session key
    SECRET_KEY = 'FuMr3MjPDLjjpgtRbRfhA1uHsMoNPcYzr6QyjtrBQvNVWHTvxRVcSLyazsKdQt4X'

    # Session配置
    SESSION_TYPE = 'redis'

    # 指定Session保存的redis
    SESSION_REDIS = StrictRedis(host=REDIS_HOST, port=REDIS_PORT)

    # Session前缀
    SESSION_KEY_PREFIX = 'fffSESSION'

    # Session签名(加密)
    SESSION_USE_SIGNER = True

    # 设置Session需要过期
    SESSION_PERMANENT = True

    # 设置Session过期事件(1天,86400秒)
    PERMANENT_SESSION_LIFETIME = 86400

    # 设置log等级
    LOG_LEVEL = logging.DEBUG


class DevelopmentConfig(Config):
    """开发环境配置"""
    DEBUG = True


class ProductionConfig(Config):
    """生产环境配置"""
    DEBUG = False

    # 配置MYSQL连接
    SQLALCHEMY_DATABASE_URI = "mysql://root:123456@127.0.0.1/information"

    # 设置log等级
    LOG_LEVEL = logging.WARNING


class TestingConfig(Config):
    """单元测试环境下的配置"""
    DEBUG = True
    TESTING = True


config = {
    "dev": DevelopmentConfig,
    "pro": ProductionConfig,
    "test": TestingConfig
}
